<%@ page import="com.engine.kq.biz.KQWorkTime" %>
<%@ page import="java.util.Map" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="java.util.Set" %>
<%@ page import="org.springframework.util.CollectionUtils" %>
<%@ page import="com.engine.kq.biz.KQGroupMemberComInfo" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.HashSet" %>
<%@ page import="weaver.conn.RecordSet" %><%

    out.println("start." + "<br>");

    String userId = request.getParameter("userId");
    String startDate = request.getParameter("startDate");
    String endDate = request.getParameter("endDate");

    List<String> result = new ArrayList<>();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

    LocalDate start = LocalDate.parse(startDate, formatter);
    LocalDate end = LocalDate.parse(endDate, formatter);

    while (!start.isAfter(end)) {
        result.add(start.format(formatter));
        start = start.plusDays(1);
    }
    // 获取公休日
    RecordSet rsTemp = new RecordSet();
    Map<String, Set<String>> groupIdRqMap = new HashMap<>();
    rsTemp.execute("select groupId, holidayDate from kq_HolidaySet where changeType = 1 and holidayDate>='" + startDate + "' and holidayDate<='" + endDate + "'");
    while (rsTemp.next()) {
        String groupIdTemp = rsTemp.getString("groupId");
        String holidayDate = rsTemp.getString("holidayDate");
        if (StringUtils.isEmpty(holidayDate) || StringUtils.isEmpty(groupIdTemp)) {
            continue;
        }
        Set<String> dateSet = new HashSet<>();
        if ((!CollectionUtils.isEmpty(groupIdRqMap)) && groupIdRqMap.containsKey(groupIdTemp)) {
            dateSet = groupIdRqMap.get(groupIdTemp);
        }
        dateSet.add(holidayDate);
        groupIdRqMap.put(groupIdTemp, dateSet);
    }
    out.println("dateSet is:" + groupIdRqMap + "<br>");

    KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo();

    int cnt = 0;
    for (String dateTemp : result) {
        String groupId = kqGroupMemberComInfo.getKQGroupId(userId, dateTemp);
        out.println("groupId is:" + groupId + "<br>");
        if (StringUtils.isEmpty(groupId)) {
            continue;
        }
        Set<String> strings = groupIdRqMap.get(groupId);
        if ((!CollectionUtils.isEmpty(strings)) && strings.contains(dateTemp)) {
            cnt = cnt + 1;
        }
    }
    out.println("cnt:" + cnt + "<br>");
%>